/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Monetario;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
/**
 *
 * @author Yojugracu
 */
public class ConexionMysql {

    Connection connectar = null;
    Statement statement = null;
    ResultSet resultSet = null;
    String driverClassName ="com.mysql.jdbc.Driver";
            String driverUrl = "jdbc:mysql://localhost:3306/banco";
            String usuario = "root";
            String contrasenia = "";

    public ConexionMysql(){
        try{
            //CargarResultados(dir()+"/Conexion.txt");
        
            Class.forName(driverClassName).newInstance();
            connectar = DriverManager.getConnection(driverUrl,
                                       usuario, contrasenia);
        }catch(Exception e){ }
    }

    public boolean GenerarSentencia(String query){
        try{
            statement = connectar.createStatement();
            statement.execute(query);
            return true;
        }catch(Exception e){ return false; }
    }

    public ResultSet GenerarR(String query){
        try{
            statement = connectar.createStatement();
            return statement.executeQuery(query);
        }catch(Exception e){ return null; }
    }

    public void EndConeccion(){
        try{ if(connectar!=null){ connectar.close(); } }catch(Exception e){}
    }

     public void Backup(){
    try {
        System.out.println("database connect");
        System.out.println("\"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysqldump\" --user="+usuario+" --pass="+contrasenia+" --opt banco> C:\\SQLServerBackups\\backup.sql");

        Runtime.getRuntime().exec("\"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysqldump\" --user="+usuario+" --pass="+contrasenia+" --opt banco> C:\\SQLServerBackups\\backup.sql");


        }

        catch(IOException ioe)
        {
        ioe.printStackTrace();
        System.out.println("pupu");
        }

        catch(Exception e) {
        e.printStackTrace();
        System.out.println("caca");
        }
    }

         public static void main(String[] args) {
             ConexionMysql miconx=new ConexionMysql();
             miconx.Backup();
    }


}
